/**
 * 
 */
package officeserver.office.request;

import java.io.Serializable;

import officeserver.office.Office;
import officeserver.office.network.RequestQueueManager;
import officeserver.office.request.UserRequest.TYPE;

/**
 * @author Chris Bayruns
 * 
 */
public class AdminRequest extends OfficeRequest implements Serializable {

    /**
	 * 
	 */
	private static final long serialVersionUID = -6991472683806649050L;

	/**
	 * 
	 */

	public enum TYPE {
	CON_DISCONNECT, LOAD, SAVE
    }

    private TYPE type;

    /**
     * @author Chris Bayruns
     */
    public AdminRequest(TYPE type, Object... myArgs) {
	this.type = type;
	this.setArgs(myArgs);
    }

    /**
     * @return the type
     */
    public TYPE getType() {
	return type;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * officeserver.office.request.OfficeRequest#processRequest(officeserver
     * .office.Office)
     */
    @Override
    public void processRequest(Office in) {
	switch (type) {
	case CON_DISCONNECT:
	    break;
	case LOAD:
	    processLoad(in);
	    break;
	case SAVE:
	    processSave(in);
	    break;
	}
    }

    /**
     * @author Chris Bayruns
     * @param in
     *            The office object to act on.
     */
    private void processLoad(Office in) {
	try {
	    RequestQueueManager.setInterupt(true);
	    Thread.sleep(2000);
	    in.load();
	    in.save();
	    RequestQueueManager.setInterupt(false);
	} catch (Exception e) {
	    error = e;
	}

    }

    /**
     * @author Chris Bayruns
     * @param in
     *            The office object to act on.
     */
    private void processSave(Office in) {
	try {
	    RequestQueueManager.setInterupt(true);
	    Thread.sleep(2000);
	    in.save();
	    RequestQueueManager.setInterupt(false);
	} catch (Exception e) {
	    error = e;
	}

    }
}
